package xju_3_4.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Aspect//切面
@Component
@Order(0)
public class XmlAdvice {

    // 切点
    @Pointcut("execution(* xju_3_4.service.impl.UserServiceImpl.*(..))")
    public void pointCut() {
    }

    // 前置通知
    @Before("pointCut()")
    public void before() {
        System.out.println("前置通知");
    }
    // 返回通知
    @AfterReturning("pointCut()")
    public void afterReturning() {
        System.out.println("返回通知");
    }
    // 环绕通知

    @Around("pointCut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        System.out.println("环绕通知之前部分");
// 调用目标方法
        Object proceed = point.proceed();
        System.out.println("环绕通知之后的部分");
        return proceed;
    }
    // 异常通知
    @AfterThrowing("pointCut()")
    public void afterException() {
        System.out.println("异常通知");
    }
    // 后置通知
    @After("pointCut()")
    public void after() {
        System.out.println("后置通知");
    }
}
